package weaver.jobs.autolink.duss.cron;

import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import weaver.jobs.autolink.duss.utils.AutolinkUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-09-02
 * @Description: 试用期目标台账发起五个月之后自动触发试用期转正审批流程
 * @ModifyLog:
 **/

public class WeaZzspdCronJob extends BaseCronJob {
    @Override
    public void execute() {
        String currentDate = DateUtil.getCurrentDate();
        BaseBean baseBean = new BaseBean();
        AutolinkUtil autolink = new AutolinkUtil();
        baseBean.writeLog(">>>>WeaZzspdCronJob>>>>>currentDate=" + currentDate);
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        RecordSet rs2 = new RecordSet();
        String tableName = "formtable_main_96";
        rs.executeQuery("select id, bkpr,zj,gw,sybm,kpr,syqksrq,syqjsrq,syqmblc from uf_syqmbtz where  cfsyqzzrq ='" + currentDate + "' and isnull(sfyfq,1) !=0");
        while (rs.next()) {
            Map<String, String> requestMainMap = new HashMap<>();
            String id = Util.null2String(rs.getString("id"));
            String bkpr = Util.null2String(rs.getString("bkpr"));
            String zj = Util.null2String(rs.getString("zj"));
            String gw = Util.null2String(rs.getString("gw"));
            String sybm = Util.null2String(rs.getString("sybm"));
            String kpr = Util.null2String(rs.getString("kpr"));
            String syqksrq = Util.null2String(rs.getString("syqksrq"));
            String syqjsrq = Util.null2String(rs.getString("syqjsrq"));
            String syqmblc = Util.null2String(rs.getString("syqmblc"));
            rs1.executeQuery("select loginid from hrmresource where id=?", bkpr);
            rs1.next();
            String loginid = Util.null2String(rs1.getString("loginid"));
            if (!"".equals(loginid)) {
                requestMainMap.put("bkpr", bkpr);
                requestMainMap.put("zj", zj);
                requestMainMap.put("gw", gw);
                requestMainMap.put("sybm", sybm);
                requestMainMap.put("kpr", kpr);
                requestMainMap.put("syqksrq", syqksrq);
                requestMainMap.put("syqjsrq", syqjsrq);
                requestMainMap.put("syqmblc", syqmblc);
                String newrequestid = autolink.createZzspdWf(bkpr, currentDate, requestMainMap);
                if (Util.getIntValue(newrequestid) > 0) {
                    String newmainid = autolink.getIdByRequestId(tableName, newrequestid);
                    baseBean.writeLog(">>>>WeaScgzrblcCronJob>>>>>newrequestid=" + newrequestid);
                    rs1.executeQuery("select rwjhjkpimbfzmf70f,fs1 from uf_syqmbtz_dt1 where mainid=?", id);
                    while (rs1.next()) {
                        Map<String, Object> requestdt1Map = new HashMap<>();
                        String rwjhjkpimbfzmf70f = Util.null2String(rs1.getString("rwjhjkpimbfzmf70f"));
                        String fs1 = Util.null2String(rs1.getString("fs1"));
                        requestdt1Map.put("rwjhjkpimbfz", rwjhjkpimbfzmf70f);
                        requestdt1Map.put("fz", fs1);
                        requestdt1Map.put("mainid", newmainid);
                        autolink.updateDetailData(tableName + "_dt1", requestdt1Map);
                    }

                    rs2.executeQuery("select nlytdmf30f,fs from uf_syqmbtz_dt2 where mainid=?", id);
                    while (rs2.next()) {
                        Map<String, Object> requestdt2Map = new HashMap<>();
                        String nlytdmf30f = Util.null2String(rs2.getString("nlytdmf30f"));
                        String fs = Util.null2String(rs2.getString("fs"));
                        requestdt2Map.put("nlytd", nlytdmf30f);
                        requestdt2Map.put("fz", fs);
                        requestdt2Map.put("mainid", newmainid);
                        autolink.updateDetailData(tableName + "_dt2", requestdt2Map);
                    }
                }
            }
        }

    }


}
